﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using NHibernate;
using NHibernate.Criterion;

namespace SmartProject.Entity
{
    public class TaskStatus : EntityBase
    {
        public virtual string Description { get; set; }

        public static TaskStatus Add(ISession session, string description)
        {
            TaskStatus taskStatus = GetTaskStatus(session, description);
            if (taskStatus == null)
            {
                taskStatus = new TaskStatus();
                taskStatus.Description = description;
            }
            taskStatus.Save(session);
            return taskStatus;
        }

        public static TaskStatus GetTaskStatus(ISession session, string description)
        {
            IList<ICriterion> expressions = new List<ICriterion>();
            expressions.Add(Restrictions.Eq("Description", description));
            IList<EntityBase> entities = Find(session, expressions, null, typeof(TaskStatus));
            if (entities != null && entities.Count == 1)
            {
                return (TaskStatus)entities[0];
            }
            return null;
        }
    }
}
